Appendix C

VBScript Reference of Syntax, Methods, and Functions


This appendix summarizes the statements, functions, and operators used in the Visual Basic Scripting Edition.

Category/KeywordType Usage
Arithmetic
AtnFunction Returns the arctangent of a number
Atn(number)
CosFunction Returns the cosine of an angle
Cos(number)
ExpFunction Returns a number raised to a power
Exp(number)
LogFunction Returns the logarithm of a number
Log(number)
RandomizeStatement Primes the internal random number generator
Randomize
(See Chapter 11, "Real-Life Examples I")
Rnd Function Returns a random number
Rnd
(See Chapter 11)
SinFunction Returns the sine of an angle
Sin(number)
SqrFunction Returns the square root of a number
Sqr(number)
TanFunction Returns the tangent of an angle
Tan(number)
Array handling
DimStatement Declares an array
Dim arrayname([subscripts])
(See Chapter 4 "Using the VBScript Language")
Erase Statement Clears the contents of an array
Erase arrayname
IsArrayFunction Returns True if var is an array, and False if not
IsArray(var)
LboundFunction In VBScript, always returns 0
Lbound(arrayname)
PreserveStatement Copies the contents of a dynamic array to a resized dynamic array
Redim Preserve arrayname(subscripts)
ReDimStatement Declares a dynamic array or redimensions a dynamic array (see Preserve)
ReDim arrayname() or
ReDim arrayname([subscripts])
UBoundStatement Returns the largest subscript of an array
Ubound(arrayname)
Assignment
= Operator Assigns a value to a variable or property variable = value
(See Chapter 4)
Set Statement Assigns an object reference to a variable
Set variable = object
Comment
RemStatement Declares the following line as a comment to be ignored by the language engine
Rem comment_text
Constants/Literals
EmptyLiteral Declares a special uninitialized variable
value variable = Empty
(See Chapter 4)
FalseConstant A Boolean value representing 0 variable = False
(See Chapter 4)
NothingLiteral Used to disassociate an object reference from a variable; used in conjunction with Set
Set variable = Nothing
(See Chapter 4)
NullLiteral Represents no valid data
variable = Null
(See Chapter 4)
TrueConstant Boolean value representing -1
variable = True
(See Chapter 4)
Conversions
AbsFunction Returns the unsigned (absolute) value of a number
Abs(number)
AscFunction Returns the ANSI/ASCII code of a character
Asc(string)
(See Chapter 3 "Communicating with Your Users")
CBoolFunction Returns a Boolean subtype Variant value from any valid expression
CBool(expression)
CByteFunction Returns a Byte subtype Variant value from any valid expression Cbyte(expression)
CDateFunction Returns a Date subtype Variant value from any valid date expression
CDate(expression)
CDblFunction Returns a Double Precision subtype Variant value from any valid numeric expression
CDbl(expression)
ChrFunction Returns the character corresponding to the ANSI or ASCII code Chr(number)
CIntFunction Returns an Integer subtype Variant value from any valid numeric expression
CInt(expression)
CLngFunction Returns a Long Integer subtype Variant value from any valid numeric expression
CLng(expression)
CSngFunction Returns a Single Precision subtype Variant value from any valid numeric expression
CSng(expression)
CStrFunction Returns a String subtype Variant value from any valid expression
CStr(expression)
DateSerialFunction Returns a Date subtype Variant from valid year, month, and day values
DateSerial(year,month,day)
DateValueFunction Returns a Date subtype Variant value from any valid date expression
DateValue(expression)
HexFunction Returns a String subtype Variant representing the hexadecimal value of a number
Hex(number)
IntFunction Returns an Integer subtype Variant rounded down from the number supplied
Int(number)
FixFunction Returns an Integer subtype Variant rounded up from the number supplied
Fix(number)
OctFunction Returns a String subtype Variant representing the octal value of a number
Hex(number)
SgnFunction Returns an Integer subtype Variant representing the sign of a number
Sgn(number)
values > 0 return 1
values = 0 return 0
values < 0 return -1
TimeSerialFunction Returns a Date subtype Variant from valid hour, minute, and second values
TimeSerial(hour,minute,second)
TimeValueFunction Returns a Date subtype Variant value from any valid time expression
TimeValue(expression)
Dates and Times
DateFunction Returns the current system date
Date()
DateSerialFunction Returns a Date subtype Variant from valid year, month, and day values.
DateSerial(year,month,day)
DateValueFunction Returns a Date subtype Variant value from any valid date expression.
DateValue(expression)
DayFunction Returns an Integer subtype Variant representing the day (1-31) from a valid date expression
Day(dateexpression)
HourFunction Returns an Integer subtype Variant representing the hour (0-23) from a valid time expression
Hour(timeexpression)
MinuteFunction Returns an Integer subtype Variant representing the minute (0-60) from a valid time expression
Minute(timeexpression)
MonthFunction Returns an Integer subtype Variant representing the month (1-12) from a valid date expression
Month(dateexpression)
NowFunction Returns the current date and time of the system
Now()
SecondFunction Returns an Integer subtype Variant representing the second (0-60) from a valid time expression
Second(timeexpression)
TimeFunction Returns the current system time Time()
TimeSerialFunction Returns a Date subtype Variant from valid hour, minute and second values
TimeSerial(hour,minute,second)
TimeValueFunction Returns a Date subtype Variant value from any valid time expression
TimeValue(expression)
WeekdayFunction Returns an Integer subtype Variant between 1 and 7 representing the day of the week, starting at Sunday, from a date expression
Weekday(dateexpression)
YearFunction Returns an Integer subtype Variant representing the year from a valid date expression
Year(dateexpression)
Declarations
DimStatement Declares a variable
Dim variable
EndStatement Declares the end of a Sub procedure or function
End Sub
End Function
ExitStatement Use with Do, For, Function, or Sub to prematurely exit the routine
Exit Do/For/Function/Sub
FunctionStatement Declares a function and the argument list passed into the function, and declares the end of a function; also used with Exit to prematurely end a function
Function functionname(argumentlist)
Exit Function
End Function
Public variable
SubStatement Declares a custom procedure or event handler and the argument list, if any, and declares the end of a custom procedure or event handler; also used with Exit to prematurely end a custom procedure or event handler
Sub subroutinename([argumentlist])
Exit Sub
End Sub
Error Handling
ClearMethod A method of the Err object to reset the Err.Number property to 0
Err.Clear
DescriptionProperty A property of the Err object that contains a description of the last error as specified in the Err.Number property
Err.Description
ErrObjectAn object containing information about the last error
Err.property|method
On Error Statement Used in conjunction with Resume Next to continue execution with the line directly following the line in which the error occurred
On Error Resume Next
RaiseMethod A method of the Err object used to simulate the occurrence of an error specified by number
Err.Raise(errornumber)
NumberProperty A property of the Err object that contains the error code for the last error, or 0 if no error has occurred
Err.Number
SourceProperty Returns the name of the object or application that raised the error
Err.Source
Input/Output
InputBoxFunction Displays a dialog box to allow user input
InputBox(caption[,title][,value][,x][,y])
MsgBoxFunction Displays a dialog box
MsgBox(prompt[, definition][, title])
Operators
+OperatorAddition of two numerical expressions
result = expr1 + expr2
AndOperator Logical conjunction operator
If expression AND expression Then
/OperatorDivision operator
result = expression / expression
=OperatorEquality operator
If expression = expression Then
EqvOperator Logical equivalence operator
If expression Eqv expression Then
^OperatorExponentiation operator
result = expression ^ expression
>Operator Greater than comparison
If expression > expression Then
>=Operator Greater than or equal to comparison
If expression >= expression Then
ImpOperator Logical implication
If expression Imp expression Then
<>Operator Inequality comparison
If expression <> expression Then
\OperatorInteger division operator
result = expression \ expression
<Operator Less than comparison
If expression < expression Then
<=Operator Less than or equal to comparison
If expression <= expression Then
ModOperator Modulus arithmetic; returns only the remainder of a division of two numbers
result = expression mod expression
*OperatorMultiplication
result = expression * expression
-OperatorSubtraction
result = expression - expression
OrOperator Logical disjunction
If expression Or expression Then
&Operator Concatenation of two string values
result = string & string
XorOperator Logical exclusion
If expression Xor expression Then
Options
OptionStatement Forces a compile-time error if an
Explicit undeclared variable is found
Option Explicit
Program Flow
CallStatement Passes execution to a subroutine or event handler; also can be used to replicate the actions of the user
Call myroutine()
Call cmdbutton_OnClick()
Do...LoopStatement Repeats code while a condition is met or until a condition is met
Do While condition
...
Loop
or
Do Until condition
...
Loop

or
Do
...
Loop While condition
or
Do
...
Loop Until condition

For...NextStatement Repeats a block of code until the counter reaches a given number
For counter = lower to upper [step]
...
Next
If...Then...ElseStatement Conditional execution of code
If condition Then
...
(if condition met
Else)
... (if condition
not met)
End If
Select CaseStatement Selective execution of code, where
  testexpression must match expression
Select Case
testexpression
Case
expression
...
Case expression
...
Case Else
End Select
While...WendStatement Execution of a code block while a condition is met
While expression
...
Wend
Strings
InStrFunction Returns the starting point of one string within another string, or 0 if not found
result = InStr(start,searched,sought)
LcaseFunction Converts a string to lowercase
result = LCase(string)
LeftFunction Returns the n leftmost characters of a string
result = LCase(string)
LenFunction Returns the length of a string
result = Len(string)
LtrimFunction Removes all leading spaces
result = LTrim(string)
MidFunction Returns a string of length L, starting at S within
string result = Mid(string, S, L)
RightFunction Returns the rightmost n characters
result = Right(string, n)
RTrimFunction Removes all trailing spaces from a string
result = RTrim(string)
SpaceFunction Returns a string consisting of n spaces result = Space(n)
StrCompFunction Returns an Integer subtype Variant representing the result of a comparison of two strings
result = StrComp(string1, string2)
string1 < string2 returns -1
string1 < string2 returns 0
string1 < string2 returns 1
StringFunction Returns a string consisting of character C, of length L
result = String(L, C)
TrimFunction Removes both leading and trailing spaces
result = Trim(string)
UCaseFunction Returns a string as uppercase alphabetical characters
result = UCase(string)
Variants
IsArrayFunction Returns True (-1) if expression is an array, and False (0) if not result = IsArray(expression)
IsDateFunction Returns True (-1) if expression is a valid date and False (0) if not
result = IsDate(expression)
IsEmptyFunction Returns True (-1) if expression equates to an Empty subtype and False (0) if not
result = IsEmpty(expression)
IsNullFunction Returns True (-1) if expression equates to a Null subtype and False (0) if not
result = IsNull(expression)
IsNumericFunction Returns True (-1) if expression is a valid numeric expression and False (0) if not
result = IsNumeric(expression)
VarTypeFunction Returns an integer representing the sub data type of a Variant
result = VarType(expression)